﻿using System;
using System.Configuration;
using System.Drawing;
using System.Windows.Forms;

namespace EIM_Accounting
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            string configXml = GetAppConfig("cfgFile");
            initSelfMenus();
        }

        /// <summary>
        /// 返回＊.exe.config文件中appSettings配置节的value项
        /// </summary>
        /// <param name="strKey"></param>
        /// <returns></returns>
        private static string GetAppConfig(string strKey)
        {
            foreach (string key in ConfigurationManager.AppSettings)
            {
                if (key == strKey)
                {
                    return ConfigurationManager.AppSettings[strKey];
                }
            }
            return null;
        }

        private void initSelfMenus()
        {
            string[] array = "EC010101,EC010102,成员列表,成员新增,成员状态变更,合同实际时间编辑,合同成员列表,节假日设定".Split(',');
            int left = 135;
            int top = 80;
            int num = 1;
            foreach (string key in array)
            {
                if (num > 7)
                {
                    top += 70;
                    left = 135;
                    num = 1;
                }
                this.panel1.Controls.Add(this.CreatButton(new System.Drawing.Point(left, top), key.Trim().ToString()));
                left += 110;
                num++;
            }
        }

        private Button CreatButton(Point point, string Text)
        {
            Button btn = new Button();
            btn.Location = point;
            btn.Name = Text;
            btn.Size = new System.Drawing.Size(95, 51);
            btn.TabIndex = 1;
            btn.Text = Text;
            btn.UseVisualStyleBackColor = true;
            btn.BackColor = System.Drawing.Color.FromArgb(167, 224, 250);
            btn.FlatAppearance.BorderColor = System.Drawing.Color.FromArgb(0, 192, 192);
            btn.ForeColor = System.Drawing.Color.FromArgb(3, 143, 143);
            btn.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
            btn.Font = new System.Drawing.Font("宋体", 11F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            btn.UseVisualStyleBackColor = false;
            btn.Click += new EventHandler(reload_Click);
            return btn;
        }

        /// <summary>
        /// 点击注册
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void reload_Click(object sender, EventArgs e)
        {
            try
            {
                string temp = sender.ToString();
                if (sender is Button)
                {
                    temp = (sender as Button).Text;
                }

                if (temp == "成员列表")
                {
                    CM010101 hfs = new CM010101();
                    hfs.ShowDialog();
                    return;
                }
                if (temp == "成员新增")
                {
                    CM010102 hfs = new CM010102();
                    hfs.ShowDialog();
                    return;
                }
                if (temp == "成员状态变更")
                {
                    CM010103 hfs = new CM010103("Out", 1);
                    hfs.ShowDialog();
                    return;
                }
                if (temp == "节假日设定")
                {
                    CM010104 hfs = new CM010104();
                    hfs.staffIDList = new BLL.CommonBll().getStaffList();
                    hfs.ShowDialog();
                    return;
                }

                if (temp == "合同实际时间编辑")
                {
                    CP010105 hfs = new CP010105();
                    hfs.contractID = "1";
                    hfs.ShowDialog();
                    return;
                }
                if (temp == "合同成员列表")
                {
                    CP010107 hfs = new CP010107();
                    hfs.ShowDialog();
                    return;
                }
                if (temp == "EC010101")
                {
                    EC010101 hfs = new EC010101();
                    hfs.ShowDialog();
                    return;
                }
                if (temp == "EC010102")
                {
                    EC010102 hfs = new EC010102();
                    hfs.ShowDialog();
                    return;
                }
                return;
            }
            catch (Exception ex)
            {
                return;
            }
        }
    }
}